package com.itheima.test2;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //创建Socket对象并指定服务器的IP地址和端口号
        Socket socket=new Socket("127.0.0.1",8888);
        //获取输出流
        OutputStream os = socket.getOutputStream();
        //发送数据
        os.write("你好".getBytes());
        //关闭输出流
        socket.shutdownOutput();

        //接收服务端返回的消息
        InputStreamReader isr = new InputStreamReader(socket.getInputStream());
        int i;
        while((i=isr.read())!=-1){
            System.out.print((char)i);
        }
        //关闭socket
        socket.close();

    }
}
